﻿using HLStock.Model;

namespace HLStock.DBAccess.AOP
{
    public class FlagCompareAction<T> : IBeforeSaveAction<T> where T : BaseModel, new()
    {
        public void Handle(BeforeSaveEventArgs<T> arg)
        {
            if (arg.DataInDb == null)
            {
                if (arg.Data.Flag != 1)
                {
                    arg.Message = "无法编辑一个不存在的档案";
                    arg.Cancle = true;
                    return;
                }
            }
            else 
            {
                if (arg.Data.Flag != arg.DataInDb.Flag + 1)
                {
                    arg.Message = "档案已经被其他人编辑";
                    arg.Cancle = true;
                    return;
                }
            }
        }
    }
}
